home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Cool Demos, SDKs, & Tools / Demos⁄Tools⁄Offers / marcmoini.com / Smart Scroll 3.5 / for Developers / SmartScrollAPI.c < prev    next >
Text File  |  1997-11-25  |  5KB  |  151 lines

  1. /*
  2.      File:        SmartScrollAPI.c
  3.  
  4.      Contains:    Smart Scroll Application Programming Interface code
  5.  
  6.      Version:    1.4
  7.  
  8.      Copyright:    © 1996, 1997 by Marc Moini, portions by Marc Menschenfreund,
  9.                 Alessandro Levi Montalcini, Marco Piovanelli and Mark Shirley (Thanks!)
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, please email Marc@Kagi.com
  13.  
  14.      Version
  15.     History:    1.4        24sep97    fixes by Marco Piovanelli
  16.                 1.3        21feb97    Same as 1.2, except a couple of "ControlHandle" definitions changed to "ControlRef"
  17. */
  18.  
  19. #ifndef __SMARTSCROLLAPI__
  20. #include "SmartScrollAPI.h"
  21. #endif
  22.  
  23. #ifndef __ERRORS__
  24. #include <Errors.h>
  25. #endif
  26.  
  27. #ifndef __GESTALT__
  28. #include <Gestalt.h>
  29. #endif
  30.  
  31. #ifndef __OSUTILS__
  32. #include <OSUtils.h>
  33. #endif
  34.  
  35. #ifndef __TRAPS__
  36. #include <Traps.h>
  37. #endif
  38.  
  39. #if PRAGMA_ALIGN_SUPPORTED
  40. #pragma options align=mac68k
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT_SUPPORTED
  44. #pragma import on
  45. #endif
  46.  
  47. #define    kgestaltSmartScroll    'MMBS'
  48.  
  49. enum
  50.     {
  51.     kSetSmartScrollInfo = 0L,
  52.     kSetSmartScrollProp,
  53.     kGetSmartScrollProp,
  54.     kDisposeAllSmartScrolls
  55.     };
  56.  
  57. typedef pascal void (*SmartScrollProcPtr) (long selector,long *result,ControlRef theScrollBar,long param1,long param2);
  58.  
  59. typedef struct {
  60.     char                privateStuff[16];
  61.     SmartScrollProcPtr    dispatchProc;
  62.     long                smartScrollSignature;
  63. } SmartScrollGestaltRec, *SmartScrollGestaltPtr;
  64.  
  65.  
  66. #if GENERATINGCFM
  67. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  68.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSmartScrollProcInfo, (selector), (result), (theControl), (param1), (param2))
  69. #else
  70. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  71.         (*(userRoutine))((selector), (result), (theControl), (param1), (param2))
  72. #endif
  73.  
  74. enum    {
  75.     uppSmartScrollProcInfo = kPascalStackBased
  76.         | STACK_ROUTINE_PARAMETER (1, SIZE_CODE(sizeof(long)))
  77.         | STACK_ROUTINE_PARAMETER (2, SIZE_CODE(sizeof(long *)))
  78.         | STACK_ROUTINE_PARAMETER (3, SIZE_CODE(sizeof(ControlRef)))
  79.         | STACK_ROUTINE_PARAMETER (4, SIZE_CODE(sizeof(long)))
  80.         | STACK_ROUTINE_PARAMETER (5, SIZE_CODE(sizeof(long)))
  81. };
  82. /****************************************************************************************/
  83.  
  84. static OSErr __SmartScrollDispatch(long selector,long *result,ControlRef theControl,long param1,long param2)
  85.     {
  86.     OSErr                     ret = paramErr;
  87.     SmartScrollGestaltPtr    ssRec = nil;
  88.  
  89. #if (!(SystemSevenOrLater | GENERATINGCFM))
  90.     if (GetOSTrapAddress (_Gestalt) != GetToolTrapAddress (_Unimplemented))
  91. #endif
  92.         if (Gestalt ( kgestaltSmartScroll, (long *)&ssRec)==noErr
  93.             && ssRec && ssRec->smartScrollSignature==kgestaltSmartScroll)
  94.             {
  95.                 CallSmartScrollProc(ssRec->dispatchProc,selector,result,theControl,param1,param2);
  96.                 ret = noErr;
  97.             }
  98.     return ret;
  99.     }
  100.     
  101. /****************************************************************************************/
  102. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  103. /*  amountVisible is a 32bit value representing the size of the portion of the document that is visible now. */
  104. /*  amountTotal is a 32bit value representing the size of the whole document. */
  105. /*  these two parameters must share the same unit (pixels, lines, characters, frames, etc). */
  106.  
  107. pascal void SetSmartScrollInfo (ControlRef theScrollBar, long amountVisible , long amountTotal)
  108.     {
  109.     long     dummy;
  110.     
  111.     (void)__SmartScrollDispatch(kSetSmartScrollInfo,&dummy,theScrollBar,amountVisible,amountTotal);
  112.     }
  113.  
  114. /****************************************************************************************/
  115. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  116. /*  proportion is a Fract value (32bit) representing the Visible/Total ratio */
  117. /*  This call has the exact same effect as SetSmartScrollInfo, you may use either one. */
  118.  
  119. pascal void SetSmartScrollProp (ControlRef theScrollBar, Fract proportion)
  120. /*
  121. Comment
  122. */
  123.     {
  124.     long     dummy;
  125.     
  126.     (void)__SmartScrollDispatch(kSetSmartScrollProp,&dummy,theScrollBar,(long)proportion,0);
  127.     }
  128.  
  129. /****************************************************************************************/
  130. /* Call this routine to get the last proportion you stored for this scrollbar. */
  131. /* the value returned will be 0 if there is an error (Smart Scroll not installed, or no value stored)  */
  132.  
  133. pascal Fract GetSmartScrollProp (ControlRef theScrollBar)
  134.     {
  135.     Fract     result = 0L;
  136.     
  137.     __SmartScrollDispatch(kGetSmartScrollProp,(long *)&result,theScrollBar,0,0);
  138.     return result;
  139.     }
  140.  
  141. /****************************************************************************************/
  142. /* Call this routine before your code Quits, to help SmartScroll */
  143. /* free the memory it reserved for the scrollbars in your Application. */
  144.  
  145. pascal void DisposeAllSmartScrolls (void)
  146.     {
  147.     long     dummy;
  148.     
  149.     (void)__SmartScrollDispatch(kDisposeAllSmartScrolls,&dummy,NULL,0,0);
  150.     }
  151.